<template>
    <div class="wy-main business-car-manage">
         <!--标题-->
       <a-row class="wy-main-title">
           <a-col :span="24">
               <p class="title-p">
                   <a-divider class="title-vertical"  type="vertical" />
          <span class="title-span" >绿色食品供应审核</span>
          <a-divider class="title-divider"  />
               </p>
           </a-col>
       </a-row>
        <!--搜素框-->
       <div>
          <span><b>农产品类型：</b></span>
          <a-select  :disabled='disabled' v-model="type" style="width: 180px;" placeholder="请选择农产品类型">
          <a-select-option value="">全部</a-select-option>
          <a-select-option v-for="(itme,index) in agriList" :key="index" :value="itme.dictKey">
            {{itme.dictValue}}
          </a-select-option>
      </a-select>
          <span><b>产地：</b></span>
          <a-input style="width:180px" :disabled='disabled' @click="departureShowMap" v-model="producePlace" placeholder='请选择农产品产地' ref="userNameInput">
      <a-icon type="environment" slot="suffix" style="color: #15837A;" />
      </a-input>
          
          <!-- <span><b>审核状态：</b></span>
          <a-select defaultValue="全部" style="width:120px">
              <a-select-option value="审核中">审核中</a-select-option>
              <a-select-option value="审核通过">审核通过</a-select-option>
              <a-select-option value="审核未通过">审核未通过</a-select-option>
          </a-select> -->
          
            <span><b>关键字：</b></span>
           <a-input style="width: 120px;" maxLength="50"  v-model="subject" placeholder="请输入关键字"></a-input>
           <a-button type="primary" style="margin-left: 10px;" @click="getAgrSource()">点击查询</a-button>
       <a-button style="margin-left: 10px;" @click="reset">重置信息</a-button>
           <a-button class="title-button" type="primary" style="float: right;min-width:80px;" @click="seeAllInfo()">批量审核</a-button>
            <!--地图Svg显示位置-->
    <map-svg ref="mapSvgDialog" @change="mapSvgCall" @distance="distanceCall"></map-svg>
       </div>
        <div class="route_choice manage_car">
           <a-table :columns="columns" :dataSource="agrdata"  :rowKey="record => record.greenFoodSupplyId"  :pagination="pagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys,onChange: onSelectChange}" @change="handleTableChange">
               
              <span slot="createTime" slot-scope="text, record">
                <span v-if="!!record.createTime">{{record.createTime.split(" ")[0]}}</span>
              </span>
              <!--操作-->
               <span slot="operation" slot-scope="text, record">
                <a href="javascript:;" class="wei_warning"  v-if="record.approvalStatus==106" @click="edit(record)">待审核</a>
                <a href="javascript:;" class="wei_primary" v-if="record.approvalStatus==107" @click="edit(record)">审核通过</a>
                <a href="javascript:;" class="wei_danger" v-if="record.approvalStatus==108" @click="edit(record)">审核不通过</a>
               </span>
           </a-table>
       </div>
      <a-modal title="绿色食品供应审核" :visible="visible" @cancel="handleCancel" width="900px" :maskClosable='false' :footer="null" >
			  <city-add v-if="visible" :datail='datail' @cancel="handleCancel" :type='type'></city-add>
		 </a-modal>
      <a-modal title="批量审核" :visible="visibleAll"  @cancel="handleCancel"  width="900px" :maskClosable='false' :footer="null" >
       <city-all v-if="visibleAll" @cancel="handleCancel" :datailAll='datailAll'></city-all>
      </a-modal>
 
    </div>
</template>

<script>
import MapSvg from '@/components/dialog/MapSvg'
import { mapState } from 'vuex'
import cityAdd from "./components/CityAdd";
import cityAll from './AgriculturalSupply'
const columns = [{
    title: '农产品供应主题',
    width: 100,
    dataIndex: 'subject',
    key: 'subject' ,
},{
    title: '农产品类型',
    width: 100,
    dataIndex: 'typeValue',
    key: 'typeValue' ,

},{
    title: '农产品名称',
    width: 100,
    dataIndex: 'name',
    key: 'name' ,
},{
    title: '产地',
    width: 100,
    dataIndex: 'producePlace',
    key: 'producePlace' ,
},{
    title: '供应价格',
    width: 100,
    dataIndex: 'price',
    key: 'price' ,

},{
    title: '发布日期',
  dataIndex: 'createTime',
  width:100,
  key: 'createTime',
    scopedSlots: {
      customRender: 'createTime'
    },
},{
    title: '操作',
  width:170,
  key: '0',
  scopedSlots: {
      customRender: 'operation'
    },
}];

export default {
    components: {
         MapSvg,
         cityAdd,
         cityAll

        
    },
    data() {
        return {
            disabled:false,
            // 地图存起止数据
            departureData: {},
            agriList:[],
            isSee:true,
            type:'',
            types:'',
            producePlace:'',
            subject:'',
            columns,
            agrdata:[],
            loading: false,
            visible:false,
            visibleAll:false,
            datail:{},
            pagination: {
              pageSizeOptions: ['10', '20', '30', '40', '100'],
              defaultCurrent: 1,
              defaultPageSize: 10,
              total:0,
              showSizeChanger: true,
              showTotal: (total, range) => `共 ${total} 条记录`
              },
            selectedRowKeys: [],
            

        }
    },
    created(){
      this.getType(29)
      this.getAgrSource()
    },
    methods: {
      //修改完毕刷新数据
				close(){
				this.visible = false
				this.getAgrSource()
			},

      //选择参数
      seeAllInfo(){
        if(this.selectedRowKeys.length){
            this.visibleAll = true;
            let logIds = [];
           for(var i=0;i<this.selectedRowKeys.length;i++){
            logIds.push({"greenFoodSupplyId":this.selectedRowKeys[i]})
           }
            this.datailAll = logIds;
          }else{
            this.$message.success('请选择需要审核的绿色食品!')
          }
      },
        distanceCall(num) {
        // this.form.setFieldsValue({ juliNum: num });
      },
            /* 省市地图代码 start */
      // 省市地图回调
      mapSvgCall(d) {
        console.log(d)
        if(d.name === 'departure') {

            this.producePlace = d.provCityArea
          this.departureData = Object.assign({}, d);
        }

      },
      departureShowMap() {
        this.$refs.mapSvgDialog.mapSvgVisible('departure', 2, '', '', '');
      },
      //查询
      getAgrSource(params={}){
        params.pageSize = this.pagination.defaultPageSize
        params.pageNum = this.pagination.defaultCurrent
       if(this.type){
         params.type = this.type
       }

       if(this.producePlace){
        params.producePlace = this.producePlace
       }
        
        if(this.subject){
          params.subject = this.subject
        }
        
//        this.$get('/info/infoVehicleinfo', params).then((r) => {
        this.$get('/info/greenFoodSupply', params).then((r) => {
          console.log(r)
          this.agrdata = r.data.data.rows
          this.pagination.total = r.data.data.total
        })
      },
        //关闭弹框
        handleCancel() {
            this.visible = false
            this.visibleAll = false
            this.selectedRowKeys = []
            this.getAgrSource()
        },
        //重置
        reset(){
          this.type = ''
          this.producePlace = '' 
          this.subject = ''
          this.getAgrSource()

        },

        //修改
        edit(data){
            this.types ='edit'
            this.visible = true
            // this.isSee = false
            this.datail = data

        },
     // 获取字典类型
      getType(type){
        this.$get('/info/commonDict', {
          dictType: type
        }).then((r) => {
          if(type == 3){
            console.log(r)
          }
          switch(type){
            case 29: this.agriList = r.data.data.rows; break;
          }
        })
      },
        //全选事件
        onSelectChange (selectedRowKeys) {
          console.log('selectedRowKeys changed: ', selectedRowKeys);
          this.selectedRowKeys = selectedRowKeys
    },
          // 表格排序 分页 筛选事件
      handleTableChange (pagination, filters, sorter) {
         this.pagination.defaultPageSize = pagination.pageSize
         this.pagination.defaultCurrent  = pagination.current
         this.getAgrSource()
      },
    }
}

</script>
<style lang="less" scoped>
  .business-car-manage {
    .route_choice {
      margin-top: 20px;
    }
  }
</style>
